<?php
/**
* @package class.mysqldb.php
* This is for MySQL database connectivity.
*
* @author Nitesh Apte
* @copyright 2010
* @version 1.0
* @access public
* @License GPL
*/

include 'interface.dbconfiginterface.php';
include 'abstract.dbconfig.php';
class MySqlDB extends DBConfig implements DBConfigInterface
{	
	/**
	* Private variables for database interaction
	*/	
	public $sql_conn;
	private $sql;
	public $sql_exec;
	public $arrays;
	private $affectedRows;

	
	/**
	* _makeConnection()
	* Connect to MySQL
	*
	* @param none
	* @return $this mixed(current connection value)
	*/
	public function _makeConnection()
	{
		try {
			$this->sql_conn = mysql_connect($this->sql_host, $this->sql_user, $this->sql_pass);
			return $this;	
		}
		catch(Exception $e) {
			trigger_error($e->getMessage());
		}
	}

	/**
	* _selectDB()
	* Select the database
	*
	* @param none
	* @return $this mixed(current database value)
	*/
	public function _selectDB()
	{
		try {
			$this->sql_select_db = mysql_select_db($this->sql_dbname, $this->sql_conn);
			return $this;
		}
		catch(Exception $e) {
			trigger_error($e->getMessage());
		}
	}
	/**
	* _executeSql()
	* Execute the query
	*
	* @param $query Query String
	* @return $this mixed(current execution value)
	*/
	public function _executeSql($query)
	{
		$this->sql = $query;
		try {
			$this->sql_exec = mysql_query($this->sql);
			return $this;
		}
		catch(Exception $e) {
			trigger_error($e->getMessage());
		}
	}

	/**
	* _fetchRows()
	* Returns the rows affected as array
	*
	* @param none
	* @return $this rows affected as array
	*/
	public function _fetchRows()
	{
		try {
			$this->rows = mysql_fetch_assoc($this->sql_exec);
			return $this;
		}
		catch(Exception $e) {
			trigger_error($e->getMessage());
		}
	}

	/**
	* _fetchArray()
	* Returns the rows affected as array
	*
	* @param none
	* @return $this rows affected as array
	*/
	public function _fetchArray()
	{
		try {
			$this->arrays = mysql_fetch_array($this->sql_exec, MYSQL_ASSOC);
			return $this;
		}
		catch(Exception $e) {
			trigger_error($e->getMessage());
		}
	}
	

	public function _affectedRows()
	{
		try {
			$this->affectedRows = mysql_affected_rows();
			return $this;
		}
		catch(Exception $e) {
			trigger_error($e->getMessage());
		}
	}

	/**
	* __destruct()
	* Destroy the MySQL connection
	*
	* @param none
	* @return none
	*/
	public function __destruct()
	{
		mysql_close($this->sql_conn);
	}
}
?>